package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo4FlatMap {

  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf()
      .setAppName("flatMap")
      .setMaster("local")

    val sc = new SparkContext(conf)

    val listRDD: RDD[String] = sc.parallelize(List("java,spark,hadoop", "spark,java,hadoop"))

    /**
      * flatMap 将一行转换成多行
      */

    val flatMapRDD: RDD[String] = listRDD.flatMap(i => {
      println("line : "+i)
      i.split(",")
    })

    flatMapRDD.foreach(println)

  }

}
